#ifndef FTP_MESSAGE_H
#define FTP_MESSAGE_H

#include <string>


namespace ftp
{

enum class FtpReplyCode : int
{
	// Reply code from RFC 959
	// https://tools.ietf.org/html/rfc959

	k200CommandOkay                             = 200,
	k500SyntaxErrorUnrecognizedCommand          = 500,
	k501SyntaxErrorParameters                   = 501,
	k202CommandNotImplementedSuperfluous        = 202,
	k502CommandNotImplemented                   = 502,
	k503CommandsBadSequence                     = 503,
	k504CommandNotImplementedForParameter       = 504,

	k110ReplyRestartMarker                      = 110,
	k211ReplySystemStatus                       = 211,
	k212DirectoryStatus                         = 212,
	k213FileStatus                              = 213,
	k214HelpMessage                             = 214,
	k215NameSystemType                          = 215,

	k120ServiceReadyInMinutes                   = 120,
	k220ServiceReadyForNewUser                  = 220,
	k221ServiceClosingControlConnection         = 221,
	k421ServiceNotAvailable                     = 421,
	k125DataCOnnectionOpenTransferStarting      = 125,
	k225DataConnectionOpenNoTransfer            = 225,
	k425ErrorOpeningDataConnection              = 425,
	k226ClosingDataConnection                   = 226,
	k426TransferAborted                         = 426,
	k227EnteringPassiveMode                     = 227,

	k230UserLoggedIn                            = 230,
	k530NotLoggedIn                             = 530,
	k331UserNameOkay                            = 331,
	k332NeedAccountForLogin                     = 332,
	k532NeedAccountForStoringFiles              = 532,
	k150FilesStatusOkayOpeningDataConnection    = 150,
	k250FileActionCompleted                     = 250,
	k257PathNameCreated                         = 257,
	k350FileActionNeedFurtherInfo               = 350,
	k450FileActionNotTaken                      = 450,
	k550ActionNotTaken                          = 550,
	k451ActionAbortedLocalError                 = 451,
	k551ActionAbortedPageTypeUnknown            = 551,
	k452ActionNotTakenInsufficientStorageSpace  = 45,
	k552FileActionAborted                       = 552,
	k553ActionNotTakenFilenameNotAllowed        = 553,
};

class FtpMessage
{
public:
	FtpMessage(FtpReplyCode code, const std::string& message)
		: code_(code),
		message_(message)
	{ }

	~FtpMessage() = default;

	FtpReplyCode replyCode() const
	{
		return code_;
	}

	std::string message() const
	{
		return message_;
	}

	std::string str() const
	{
		return std::to_string(static_cast<int>(code_)) + " " + message_ + "\r\n";
	}

	std::string strWithoutCrlf() const
	{
		std::string s = str();
		return s.substr(0, s.size() - 2);
	}

private:
	FtpReplyCode code_;
	std::string message_;
};

} // namespace ftp


#endif // !FTP_MESSAGE_H
